"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.User_Coins_HistoryDao = void 0;
const DbConfig_1 = require("../../src/config/DbConfig");
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
const ResponseModel_1 = require("../../src/model/ResponseModel");
class User_Coins_HistoryDao extends DaoBase_1.DaoBase {
    static add_user_coins_history(param) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = param["userid"];
            let coins = param["coins"];
            let left_coins = param["left_coins"];
            let reseason = param["reseason"];
            let detail = param["detail"];
            let time = param["time"];
            let sql = `INSERT INTO t_user_coins_history(userid, coins, left_coins, reseason, time, detail) VALUES(?,?,?,?,?,?) ;`;
            let sqlParams = [userid, coins, left_coins, reseason, time, detail];
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let results = yield client.queryPromise(sql, sqlParams);
            if (results && results["affectedRows"] > 0) {
                return true;
            }
            else {
                return false;
            }
        });
    }
    static clear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let sql = "delete from t_user_coins_history where time < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
    static get_coins_detail(pagenum, pagesize, userid, startTime, endTime) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.DB_NAME);
            let start = (pagenum - 1) * pagesize;
            let sql = "select * from t_user_coins_history WHERE time >= ? and time < ?  ";
            let sqlParams = [startTime, endTime, start, pagesize];
            if (userid > 0) {
                // sql += " and userid=" + userid
                sql = "select * from t_user_coins_history WHERE userid=?";
                sqlParams = [userid, start, pagesize];
            }
            sql += " order by time desc ";
            sql += " limit ?,?";
            let results = yield client.queryPromise(sql, sqlParams);
            // Logger.log("results===", results)
            sql = "select count(*) as count from t_user_coins_history  WHERE time >= ? and time < ?";
            sqlParams = [startTime, endTime];
            if (userid > 0) {
                sql = "select count(*) as count from t_user_coins_history  WHERE userid >= ?";
                sqlParams = [userid];
            }
            let resultObj = {
                "data": results,
            };
            results = yield client.queryPromise(sql, sqlParams);
            let count = results[0]["count"];
            resultObj["count"] = count;
            respModel.data = resultObj;
            return respModel;
        });
    }
}
exports.User_Coins_HistoryDao = User_Coins_HistoryDao;
User_Coins_HistoryDao.DB_NAME = DbConfig_1.DbConfig.Db_Name.db_admin;
